package com.tongyu.customappbar;

import android.os.Bundle;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.tongyu.customappbar.common.Constant;
import com.tongyu.customappbar.custom.MyAppBar;
import com.tongyu.customappbar.custom.MyItemBean;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity implements MyAppBar.MyListener {

    private MyAppBar myAppBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        myAppBar.addItem(new MyItemBean().setBar_title("首页"))
                .addItem(new MyItemBean().setBar_title("同城"))
                .addItem(new MyItemBean().setBar_img(R.drawable.camera))
                .addItem(new MyItemBean().setBar_title("消息"))
                .addItem(new MyItemBean().setBar_title("我")).build();
        myAppBar.selected(0);//默认选中状态
    }

    private void initView() {
        myAppBar = (MyAppBar) findViewById(R.id.my_app_bar);
        myAppBar.setMyListener(this::select_clicked);
    }

    @Override
    public void select_clicked(int position) {
        myAppBar.selected(position);
        switch (position){
            case Constant.HOME_FRAGMENT:
                Toast.makeText(this, "首页" + position, Toast.LENGTH_SHORT).show();
                break;
            case Constant.CITY_FRAGMENT:
                Toast.makeText(this, "同城" + position, Toast.LENGTH_SHORT).show();
                break;
            case Constant.CAMERA:
                Toast.makeText(this, "相机" + position, Toast.LENGTH_SHORT).show();
                break;
            case Constant.MESSAGE_FRAGMENT:
                Toast.makeText(this, "消息" + position, Toast.LENGTH_SHORT).show();
                break;
            case Constant.MINE_FRAGMENT:
                Toast.makeText(this, "我" + position, Toast.LENGTH_SHORT).show();
                break;
        }
    }
}